<%@page import="com.award.model.User"%>
<%@page import="com.award.model.Winner"%>
<%@page import="com.award.jdbc.dao.JdbcDao"%>
<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
JdbcDao jd = new JdbcDao();
List<Winner> winner = jd.queryAllWinner();
List<Winner> winner_oneDay = new ArrayList<Winner>();
List<Winner> winner_oneWeek = new ArrayList<Winner>();
List<Winner> winner_oneMonth = new ArrayList<Winner>();
User uuu=null;
Date date = new Date();
Date oneDayBefore = new Date(date.getTime()-86400000);
Date oneWeekBefore = new Date(date.getTime()-86400000*7);
Date oneMonthBefore = new Date(date.getTime()-86400000*15-86400000*15);
boolean join=true;
//增加一天的
for(Winner w:winner){
join=true;
if(w.getWinTime().getTime()>oneDayBefore.getTime())
{
for(Winner wn:winner_oneDay){
if(wn.getWinnerID()==w.getWinnerID()){
wn.setCommodityPrice(wn.getCommodityPrice()+w.getCommodityPrice());
wn.setRaffleNum(wn.getRaffleNum()+1);
join=false;
}
}
if(true==join){
w.setRaffleNum(1);
winner_oneDay.add(w);
}
}
}
//增加一周的
for(Winner w:winner_oneDay){
winner_oneWeek.add(w);
}
for(Winner w:winner){
join=true;
if(w.getWinTime().getTime()>oneWeekBefore.getTime() && w.getWinTime().getTime()<oneDayBefore.getTime())
{
for(Winner wn:winner_oneWeek){
if(wn.getWinnerID()==w.getWinnerID()){
wn.setCommodityPrice(wn.getCommodityPrice()+w.getCommodityPrice());
wn.setRaffleNum(wn.getRaffleNum()+1);
join=false;
}
}
if(true==join){
w.setRaffleNum(1);
winner_oneWeek.add(w);
}
}
}

//增加一月的
for(Winner w:winner_oneWeek){
winner_oneMonth.add(w);
}
for(Winner w:winner){
join=true;
if(w.getWinTime().getTime()>oneMonthBefore.getTime()&&w.getWinTime().getTime()<oneWeekBefore.getTime())
{
for(Winner wn:winner_oneMonth){
if(wn.getWinnerID()==w.getWinnerID()){
wn.setCommodityPrice(wn.getCommodityPrice()+w.getCommodityPrice());
wn.setRaffleNum(wn.getRaffleNum()+1);
join=false;
}
}
if(true==join){
w.setRaffleNum(1);
winner_oneMonth.add(w);
}
}
}
Collections.sort(winner_oneDay);
Collections.sort(winner_oneWeek);
Collections.sort(winner_oneMonth);
%>

<!DOCTYPE html>
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'leaderboards.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<link href="./css/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link href="./css/flat-ui.min.css" rel="stylesheet">
    <link href="./css/style.min.css" rel="stylesheet">

  </head>
  
  <body>
<jsp:include page="border/header.jsp" flush="true"></jsp:include>
<div class="container">
    <div class="title-page">
        <h1>TOP 10</h1>
    </div>
    <div id="leaderboards" class="container">
        <div>
            <!-- Nav tabs -->
            <ul class="nav nav-tabs nav-justified" role="tablist">
                <li role="presentation">
                    <a href="#tab1" aria-controls="tab1" role="tab" data-toggle="tab">24小时</a>
                </li>
                <li role="presentation" class="active">
                    <a href="#tab2" aria-controls="tab2" role="tab" data-toggle="tab">7天</a>
                </li>
                <li role="presentation">
                    <a href="#tab3" aria-controls="tab3" role="tab" data-toggle="tab">30天</a>
                </li>
            </ul>

            <!-- Tab panes -->
            <div class="tab-content">
                <div role="tabpanel" class="tab-pane" id="tab1">
                    <div class="list-leaders">
                        <ul>
                        <% 
                        for(int i=0;i<10&&i<winner_oneDay.size();i++){
                        uuu = jd.queryEmployeeByID(winner_oneDay.get(i).getWinnerID());
                         %>
                            <li>
                                <a href="./jsp/leaderboards.jsp">
                                	<span class="leader-number"><%= i+1 %></span>
                                    <img class="leader-img" src="<%= uuu.getUserImgURL() %>">
                                    <span class="leader-name"><%= uuu.getUsername() %></span>
                                    <span class="leader-name"></span>
                                    <span class="leader-wins"><strong>总金额：</strong>￥<%= winner_oneDay.get(i).getCommodityPrice() %></span>
                                    <span class="leader-won"><strong>奖品数量：</strong><%= winner_oneDay.get(i).getRaffleNum() %></span>
                                </a>
                            </li>
                            <%} %>
                        </ul>
                    </div>
                </div>
                <div role="tabpanel" class="tab-pane active" id="tab2">
                    <div class="list-leaders">
                        <ul>
                        <% for(int i=0;i<10&&i<winner_oneWeek.size();i++){ 
                        uuu = jd.queryEmployeeByID(winner_oneWeek.get(i).getWinnerID());%>
                            <li>
                                <a href="./jsp/leaderboards.jsp">
                                	<span class="leader-number"><%= i+1 %></span>
                                    <img class="leader-img" src="<%=uuu.getUserImgURL()%>">
                                    <span class="leader-name"><%= uuu.getUsername() %></span>
                                    <span class="leader-name"></span>
                                    <span class="leader-wins"><strong>总金额：</strong>￥<%= winner_oneWeek.get(i).getCommodityPrice() %></span>
                                    <span class="leader-won"><strong>奖品数量：</strong><%= winner_oneWeek.get(i).getRaffleNum() %></span>
                                </a>
                            </li>
                            <%} %>
                        </ul>
                    </div>
                </div>
                <div role="tabpanel" class="tab-pane" id="tab3">
                    <div class="list-leaders">
                        <ul>
                        <% for(int i=0;i<10&&i<winner_oneMonth.size();i++){ 
                        uuu = jd.queryEmployeeByID(winner_oneMonth.get(i).getWinnerID());%>
                            <li>
                                <a href="./jsp/leaderboards.jsp">
                                	<span class="leader-number"><%= i+1 %></span>
                                    <img class="leader-img" src="<%=uuu.getUserImgURL()%>">
                                    <span class="leader-name"><%= uuu.getUsername() %></span>
                                    <span class="leader-name"></span>
                                    <span class="leader-wins"><strong>总金额：</strong>￥<%= winner_oneMonth.get(i).getCommodityPrice() %></span>
                                    <span class="leader-won"><strong>奖品数量：</strong><%= winner_oneMonth.get(i).getRaffleNum() %></span>
                                </a>
                            </li>
                            <%} %>
                        </ul>
                    </div>
                </div>
            </div>

        </div>
    </div>
</div>
<footer>
    <div>
        Copyright &copy; 2017
    </div>
</footer>

<script src="./js/jquery.min.js"></script>
<script src="./js/flat-ui.min.js"></script>
<script src="./js/script.js"></script>
<script>
	$('.nav-item-leaderboards').addClass("active");
</script>
</body>
</html>
